<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class SStuTaskInfo extends Model
{
    //

    use SoftDeletes;
    public $table = "s_stu_task_info";

    protected $fillable = [
        'user_id', 'task_id', 'teacher_id', 'admin_id', 'feed_back_id', 'status', 'content', 'pics', 'voices', 'evaluation', 'audit_time', 'eva_time', 'created_at', 'updated_at'
    ];

    public function users()
    {
        return $this->belongsTo('App\User', 'user_id');
    }

    public function tasks()
    {
        return $this->belongsTo('App\Models\STaskInfo', 'task_id');
    }

    public function adminUsers()
    {
        return $this->belongsTo('App\Models\AdminUsers', 'admin_id');
    }

    public function feedBacks()
    {
        return $this->belongsTo('App\Models\SLessonFeedback', 'feed_back_id');
    }


    static public function getStuTaskList($user_id, $status, $offset=0, $limit=5)
    {
        if($status == -1){
            $where = [
                ['user_id', $user_id],
            ];
        } else {
            $where = [
                ['user_id', $user_id],
                ['status', $status],
            ];
        }
        
        return self::where($where)
        ->offset($offset)
        ->limit($limit)
        ->get();
    }
}
